package pl.mchaniewski.ryneczek.utilities;

import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

public class FacesMessageUtil {

    public static void addMessage(String msg) {
        FacesMessage message = new FacesMessage(msg);
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, message);
    }

    public static void addMessage(String clientId, FacesMessage msg) {
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(clientId, msg);
    }

    public static void addMessage(UIComponent component, String msg) {
        FacesMessage message = new FacesMessage(msg);
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(component.getClientId(context), message);
    }

    public static void addMessage(UIComponent component, String msg,
            Severity severity) {
        FacesMessage message = new FacesMessage(severity, msg, null);
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(component.getClientId(context), message);
    }

    public static void addMessage(String msg, Severity severity) {
        FacesMessage message = new FacesMessage(severity, msg, null);
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, message);
    }

}
